//
//  FPSettleModel.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/2/19.
//

#import "FPSettleModel.h"

@implementation FPSettleModel

+ (JSONKeyMapper *)keyMapper {
    
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"ID" : @"id"}];
}

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
}



+ (void)getSettleListInfoSuccess:(void (^)(NSInteger, NSString * _Nonnull, NSArray * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    NSMutableDictionary *param = APIClient.creatAPIDictionary;
    
    [param setObject:@"1" forKey:@"status"];
    
    NSString *urlStr = [APIClient getQueryURLStringWithParam:param URLString:SETTILE_LIST_URL];
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:urlStr] parameters:param type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        NSArray *list = [FPSettleModel arrayOfModelsFromDictionaries:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message , list);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}


+ (void)getSettleDetailWithID:(NSString *)ID success:(void (^)(NSInteger, NSString * _Nonnull, FPSettleModel * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    NSMutableDictionary *param = APIClient.creatAPIDictionary;
    
    [param setObject:ID forKey:@"id"];
    
    NSString *urlStr = [APIClient getQueryURLStringWithParam:param URLString:SETTLE_DETAIL_URL];
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:urlStr] parameters:param type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        FPSettleModel *model = [[FPSettleModel alloc] initWithDictionary:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message , model);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}





@end
